package genedit.gui.propertyDialogs;

import genedit.gui.GMainFrame;
import genedit.gui.exceptions.ElementNePostoji;
import genedit.gui.exceptions.ElementPostoji;
import genedit.model.graph.Property;
import genedit.model.graph.classModel.AssociationLink;
import genedit.model.graph.classModel.ClassModel;
import genedit.model.graph.classModel.GAttribute;
import genedit.model.graph.classModel.GAttributes;
import genedit.model.graph.classModel.GMethod;
import genedit.model.graph.classModel.GMethods;
import genedit.model.graph.classModel.GeneralizationLink;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;

@SuppressWarnings("serial")
public class GeneralizationLinkDialog  extends JDialog {
	
	protected JFrame parent;
	protected GMainFrame mf = GMainFrame.getInstance();
	protected GeneralizationLink linkGeneralization;
	protected JButton btnOkDialog;
	protected PanelDetailGeneralizationLink panelAssociation;
	
	public GeneralizationLinkDialog(JFrame parent, GeneralizationLink link) {
		super(parent, true);
		
		linkGeneralization = link;
		this.parent = parent;
		
		setTitle(linkGeneralization.getName());		
		setSize(mf.getWidth()/3, 2*mf.getHeight()/5);
		setLocationRelativeTo(parent);
		
		panelAssociation = new PanelDetailGeneralizationLink(linkGeneralization);
		add(panelAssociation, BorderLayout.CENTER);
		
		JPanel panSouth = new JPanel();
		panSouth.setLayout(new BoxLayout(panSouth, BoxLayout.PAGE_AXIS));
		 btnOkDialog = new JButton(GMainFrame.getInstance().getResourceBundle().getString("btnOk"));
		 btnOkDialog.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
						linkGeneralization.setName(panelAssociation.getTxtName().getText());
						
						setVisible(false);
			}
		});
		 btnOkDialog.setAlignmentX( 
				Component.CENTER_ALIGNMENT); 
		panSouth.add(Box.createVerticalGlue()); 
		panSouth.add(btnOkDialog); 
		panSouth.add(Box.createVerticalGlue());;
		add(panSouth, BorderLayout.SOUTH);
		
		pack();
	}
}
